package cn.wonderland.base.controller;

import cn.wonderland.base.dto.EmailCodeDto;
import cn.wonderland.base.dto.EmailRegisterDto;
import cn.wonderland.base.dto.PhoneRegisterDto;
import cn.wonderland.base.dto.SmsCodeDto;
import cn.wonderland.base.service.VerifyCodeService;
import cn.wonderland.base.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private VerifyCodeService verifyCodeService;

    // 获取图形验证码
    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult getImageCode(@PathVariable("imageCodeKey") String imageCodeKey) throws IOException {
        String imageCode = verifyCodeService.getImageCode(imageCodeKey);
        return AjaxResult.me().success(imageCode);
    }

    // 获取手机验证码
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid SmsCodeDto dto) {
        verifyCodeService.smsCode(dto);
        return AjaxResult.me().success();
    }

    // 手机号注册
    @PostMapping("/phoneRegister")
    public AjaxResult phoneRegister(@RequestBody @Valid PhoneRegisterDto dto) {
        verifyCodeService.phoneRegister(dto);
        return AjaxResult.me().success();
    }

    // 获取邮箱验证码
    @PostMapping("/emailCode")
    public AjaxResult emailCode(@RequestBody @Valid EmailCodeDto dto) {
        verifyCodeService.emailCode(dto);
        return AjaxResult.me().success();
    }

    // 手机号注册
    @PostMapping("/emailRegister")
    public AjaxResult emailRegister(@RequestBody @Valid EmailRegisterDto dto) {
        verifyCodeService.emailRegister(dto);
        return AjaxResult.me().success();
    }


}
